package com.example.wtt.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.wtt.controller.dto.DynamicDTO;
import com.example.wtt.controller.dto.HomeDTO;
import com.example.wtt.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {
//    @Select("SELECT u.id AS user_id, u.username, u.avatar, d.dynamic_id, d.dynamic_url, d.title, d.collect, d.create_time AS dynamic_create_time, d.upvote, d.user_id AS dynamic_user_id FROM sys_user u LEFT JOIN dynamic d ON u.id = d.user_id WHERE d.dynamic_id IS NOT NULL ORDER BY d.upvote DESC;")
    @Select("SELECT u.id AS user_id, d.dynamic_id, u.username, u.user_status, u.avatar AS avatar_url, d.dynamic_url, d.dynamic_text, d.create_time AS dynamic_create_time, d.title, d.collect, d.upvote FROM sys_user u JOIN dynamic d ON u.id = d.user_id ORDER BY d.upvote DESC;")
    List<DynamicDTO> findHome();

    @Select("SELECT u.id AS user_id, u.avatar, u.username, d.dynamic_id, d.dynamic_url, d.title, d.dynamic_text, d.create_time, d.upvote, d.collect, d.downvote FROM dynamic d JOIN dc ON d.dynamic_id = dc.dynamic_id JOIN sys_user u ON d.user_id = u.id WHERE dc.user_id = #{userId};")
    List<DynamicDTO> dynamicCollect(Integer userId);

    @Update("update sys_user set usage_times = null, user_status = 1 where id = #{userId}")
    Integer becomeVip(Integer userId);
//    @Select("select arrearage from sys_arrearage where id = #{id}")
//    Integer warn(Integer id);
//
//    @Update("update sys_user set balance = balance + #{money} where id = #{id}")
//    Integer recharge(Object object);

//    @Select("select * from sys_user")
//    List<User> findAll();
//
//    @Insert("INSERT  into sys_user(username,password,nickname,email,phone,address) values (#{username},#{password}," +
//            "#{nickname},#{email},#{phone},#{address})")
//    int insert(User user);
//
//    int update(User user);
//
//    @Delete("delete from sys_user where id = #{id}")
//    Integer deleteById(@Param("id") Integer id);
//
//    @Select("select * from sys_user where username like concat('%',#{username},'%')  limit #{pageNum}, #{pageSize}")
//    List<User> selectPage(Integer pageNum, Integer pageSize, String username);
//
//    @Select("select count(*) from sys_user where username like concat('%',#{username},'%')")
//    Integer selectTotal(String username);
}
